package net.sky.oa.dao.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import net.sky.oa.dao.SkyBaseDaoImpl;
import net.sky.oa.dao.system.SysPostDao;
import net.sky.oa.model.SysPost;

@SuppressWarnings("unchecked")
@Repository
public class SysPostDaoImpl extends SkyBaseDaoImpl<SysPost> implements SysPostDao {
	
	public SysPostDaoImpl() {
		super.setPersistType(SysPost.class);
	}

	public List<SysPost> findAllPost() {
		String hql = "from SysPost s";
		return findByHql(hql);
	}
	/**
	 * 岗位列表
	 */
	public List<SysPost> comboPost(String deptId) {
		StringBuilder hql=new StringBuilder("select new SysPost(s.id,s.name) from SysPost s where s.status = 1 and s.id>0");
		List list=new ArrayList();
		if(StringUtils.isNotEmpty(deptId))
		{
			hql.append(" and s.dept.id=?");
			list.add(Long.valueOf(deptId));
		}
		return findByHql(hql.toString(),list.toArray());
	}
	
	public List<SysPost> findByName(String name){
		String hql = "from SysPost d where d.name=?";
		Object[] params = { name };
		return findByHql(hql, params);
	}
}